//
 

#import "NT_HomeCollectionViewCell.h"

//
@interface NT_HomeCollectionViewCell ()
/** 图标*/
@property (nonatomic, strong) UIImageView *IMG;
/** 内容*/
@property (nonatomic, strong) UILabel *titleLabel;
/** shijian*/
@property (nonatomic, strong) UILabel *dateLabel;


@end

@implementation NT_HomeCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame {
    if ([super initWithFrame:frame]) {
        [self setUpView];
    }
    return self;
}
//
-(void)setUpView {
    //
    self.IMG =  ({
        UIImageView *img = [[UIImageView alloc]init];
        img.backgroundColor = [UIColor lightGrayColor];
        [self.contentView addSubview:img];
        img;
    });
    self.titleLabel = ({
        UILabel *label = [[UILabel alloc]init];
        label.textColor = rgba(60, 60, 60, 1);
        label.font = FontPFRegular(kRelativeWidth(18));
        label.text = @"222222";
        [self.contentView addSubview:label];
        label;
    });
    self.dateLabel = ({
        UILabel *label = [[UILabel alloc]init];
        label.textColor = rgba(90, 90, 90, 1);
        label.font = FontPFRegular(kRelativeWidth(14));
        label.text = @"2222";
        [self.contentView addSubview:label];
        label;
    });
    self.selectButton = ({
        UIButton *button = [[UIButton alloc]init];
        [button setImage:[UIImage imageNamed:@"ic_choose_nor"] forState:UIControlStateNormal];
        [button setImage:[UIImage imageNamed:@"ic_choose_select"] forState:UIControlStateSelected];
        [button addTarget:self action:@selector(Action:) forControlEvents:UIControlEventTouchUpInside];
        button.hidden = YES;
        [self.contentView addSubview:button];
        button;
    });
    [self setNeedsLayout];
    
}

- (void)setNeedsLayout {
    [super setNeedsLayout];
    
    [self moreFrame];
}

//多个
- (void)moreFrame {//mas_updateConstraints
    [self.IMG mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_offset(kRelativeHeight(10));
        make.left.mas_offset(kRelativeWidth(12));
        make.right.mas_offset(-kRelativeWidth(12));
        make.bottom.mas_equalTo(self.contentView.mas_bottom).offset(-kRelativeWidth(70));
    }];
    [self.titleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.IMG.mas_bottom).offset(kRelativeHeight(10));
        make.left.mas_offset(kRelativeWidth(12));
        make.right.mas_offset(-kRelativeWidth(12));
        make.height.mas_equalTo(kRelativeWidth(20));
    }];
    [self.dateLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(kRelativeHeight(10));
        make.left.mas_equalTo(self.titleLabel);
        make.height.mas_equalTo(kRelativeHeight(20));
    }];
    [self.selectButton mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.dateLabel);
        make.right.mas_offset(-kRelativeWidth(10));
        make.width.height.mas_equalTo(kRelativeWidth(35));
    }];
    
}
//
- (void)Action:(UIButton*)button {
    if ([self.delegate respondsToSelector:@selector(sendCollectCell:)]) {
        [self.delegate sendCollectCell:self];
    }
}
//MARK:s
- (void)setModel:(Note *)model {
    _model = model;
    
    //
    self.IMG.image = (UIImage*)model.img;
    self.titleLabel.text = model.title;
    self.dateLabel.text = model.date;
    //
    if ([model.status isEqual:@"1"] ) {
        self.selectButton.selected = YES;
    }else
        self.selectButton.selected = NO;
    
}


@end
